<template>
  <div class="page-container">
    <div class="container-search">
      <el-input
        v-model="input"
        class="container-item"
        placeholder="请输入订单号"
      />
      <el-input
        v-model="input"
        class="container-item"
        placeholder="请输入服务商名称"
      />
      <el-input
        v-model="input"
        class="container-item"
        placeholder="请输入用户名称"
      />

      <el-select
        v-model="FormData.type"
        clearable
        style="width: 200px"
        placeholder="核销状态"
      >
        <el-option
          v-for="(item, index) in statusMap"
          :key="index"
          :label="item.name"
          :value="item.value"
        />
      </el-select>

      <el-date-picker
        v-model="value1"
        style="margin-right:10px;width:400px"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      />
      <el-button
        type="primary"
        icon="el-icon-search"
        @click="handleFilter"
      >查询</el-button
      >
    </div>

    <el-table :data="list" border style="width: 100%">
      <el-table-column
        align="center"
        clearable
        prop="orderId"
        label="订单号"
        width="180"
      />
      <el-table-column
        align="center"
        clearable
        prop="service"
        label="服务商名称"
        width="180"
      />
      <el-table-column
        align="center"
        clearable
        prop="customer"
        label="用户名称"
      />
      <el-table-column align="center" clearable prop="status" label="核销状态">
        <template slot-scope="scope">
          <el-tag :type="scope.row.status == 1 ? 'danger' : 'info'">
            {{ scope.row.status == 1 ? "已核销" : "未核销" }}</el-tag
        ></template
        >
      </el-table-column>
      <el-table-column
        align="center"
        clearable
        prop="payMoney"
        label="需支付金额"
      />
      <el-table-column align="center" prop="date" label="日期" />
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button
            :disabled="scope.row.isverification == 1"
            size="mini"
            type="danger"
            @click="handleDetail(scope.row.id)"
          >核销</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      :visible.sync="dialogVisible"
      :before-close="handleClose"
      title="核销订单"
      width="40%"
    >
      <el-form :model="FormData" label-position="left" label-width="100px">
        <el-form-item label="订单编号：">{{ FormData.orderId }} </el-form-item>
        <el-form-item label="商品名称：">{{ FormData.name }} </el-form-item>
        <el-form-item label="订单状态：">
          <el-tag :type="statusColor(FormData.freight)">{{
            FormData.freight
          }}</el-tag>
        </el-form-item>
        <el-form-item label="订单渠道：">{{ FormData.phone }} </el-form-item>
        <el-form-item label="支付渠道：">
          <el-tag :type="payColor(FormData.pay)">{{ FormData.pay }}</el-tag>
        </el-form-item>
        <el-form-item label="配送费用：">{{ FormData.cost }} </el-form-item>
        <el-form-item label="收货信息：">{{ FormData.address }} </el-form-item>
        <el-form-item label="优惠券信息：">
          <el-select
            v-model="FormData.type"
            clearable
            style="width: 200px"
            placeholder="请选择优惠券类型"
          >
            <el-option
              v-for="(item, index) in couponTypeMap"
              :key="index"
              :label="item.name"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="changeStatus">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>

export default {
  data() {
    return {
      value1: '',
      // isverification:false,
      list: [
        {
          id: 1,
          service: '百事',
          customer: '马克思',
          status: 1,
          payMoney: '200',
          date: '2022-8-30',
          orderId: 'Am146461321',
          name: 'polo衫',
          freight: '已发货',
          phone: 'IOS',
          pay: '线下支付',
          cost: '10元',
          address:
            '（收货人）魏朝正 （手机号）18584669549 （地址）内蒙古自治区包头市青山区123123123123',
          isverification: 1
        },
        {
          id: 2,
          service: '美年达',
          customer: '玛卡巴卡',
          status: 2,
          payMoney: '2000',
          date: '2022-8-31',
          orderId: 'Ab24554623',
          name: 'polo衫',
          freight: '未发货',
          phone: 'iphone',
          pay: '微信零钱',
          cost: '免运费',
          address:
            '（收货人）小点点 （手机号）13415214701 （地址）广东省珠海市高新区12312',
          isverification: 2
        }
      ],
      FormData: {},
      couponTypeMap: [
        {
          name: '满100减10',
          value: 1
        },
        {
          name: '满200减30',
          value: 2
        }
      ],
      statusMap: [{ value: 1, name: '已核销' }, { value: 2, name: '未核销' }],
      dialogVisible: false,
      listQuery: {
        pageNo: 1,
        limit: 20,
        type: undefined,
        status: undefined,
        title: undefined
      }
    }
  },

  methods: {
    handleFilter(e) {
      console.log(e, this.list)
    },
    payColor(payChannel) {
      if (!payChannel) {
        return 'info'
      }
      if (payChannel === '微信零钱') {
        return 'success'
      } else if (payChannel === '支付宝') {
        return 'primary'
      } else if (payChannel === '线下支付') {
        return 'warning'
      } else {
        return 'danger'
      }
    },
    statusColor(statusChannel) {
      if (statusChannel === '已发货') {
        return 'primary'
      } else if (statusChannel === '未发货') {
        return 'warning'
      } else if (statusChannel === '退款中') {
        return 'danger'
      } else {
        return 'info'
      }
    },
    handleDetail(id) {
      this.dialogVisible = !this.dialogVisible
      for (var i = 0; i < this.list.length; i++) {
        if (id === this.list[i].id) {
          this.FormData = this.list[i]
        }
      }
      // this.isverification = true
    },
    changeStatus() {
      this.dialogVisible = false
      for (var i = 0; i < this.list.length; i++) {
        this.list[i].isverification = 1
        this.list[i].status = 1
      }
    }
  }
}
</script>

<style scoped>
.page-container {
  margin: 15px;
}
.container-search {
  margin-bottom: 20px;
}
.container-item {
  width: 200px;
  padding-right: 10px;
}
</style>
